package cn.laixueit.controller;

import cn.laixueit.pojo.ClassInfo;
import cn.laixueit.service.ClassService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Controller
@RequestMapping("/class")
@Scope("prototype")
public class ClassController {
    @Autowired
    private ClassService classService;

    @RequestMapping("/save")
    public String save(ClassInfo classInfo){
        classService.save(classInfo);
        return "redirect:findall";
    }

    @RequestMapping("/findall")
    public String findall(@RequestParam(defaultValue = "1")Integer startpage, @RequestParam(defaultValue = "10")Integer pagesize, @ModelAttribute ClassInfo classInfo, Model model){
        PageInfo<ClassInfo> pageInfo =  classService.findall(startpage,pagesize,classInfo);
        model.addAttribute("pageInfo",pageInfo);
        List<ClassInfo> classInfoList = classService.selectall();
        model.addAttribute("classList",classInfoList);
        return "classList";
    }
}
